home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 37
/
Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso
/
Aminet
/
dev
/
basic
/
Mildred.lha
/
lha
/
Remap.lha
/
Merge.ascii
next >
Wrap
Text File
|
1999-03-07
|
8KB
|
269 lines
WBStartup
DEFTYPE.w
MCPU Processor
Mc2pCPUmode Processor
*ScrVP._ViewPort=0
IsAGA.b=False
Dim PlanarBuf.l(2) ; Base address of planar memory to output c2p to (allowed up to triple buffers)
PrefDisplayID.l=$0 ; Default ModeID
PrefDisplayWidth.w=320 ; Default Width
PrefDisplayHeight.w=240 ; Default Height
PrefDisplayBuffering.b=1 ; 1..3. 1=Singlebuffered, 2=Doublebuffered, 3=Triplebuffered
SMRMinX=320 ; Minimum width
SMRMinY=240 ; Minimum height
SMRMaxX=640 ; Maximum width
SMRMaxY=480 ; Maximum height
;Either include SMR.bb2, or set PrefDisplayID, Width and Height to valid numbers (read from a prefs file?)
INCLUDE "SMR.bb2"
Function.b InitDisplay{Title$}
;Creates a display for AGA or Graphics-Card output
;Title$=The screen title (not displayed)
SHARED PrefDisplayWidth.w,PrefDisplayHeight.w,PrefDisplayBuffering.b
SHARED *ScrVP._ViewPort,PrefDisplayID.l,IsAGA.b,PlanarBuf()
;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
Dim ScrTags.TagItem(13)
Rect.Rectangle\MinX=0,0,320,240 ; For test
ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
ScrTags(1)\ti_Tag=#SA_Height,240; For test
ScrTags(2)\ti_Tag=#SA_Depth,8
ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
ScrTags(4)\ti_Tag=#SA_Type,$F
ScrTags(5)\ti_Tag=#SA_Quiet,True
ScrTags(6)\ti_Tag=#SA_ShowTitle,False
ScrTags(7)\ti_Tag=#SA_Behind,True
ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
ScrTags(9)\ti_Tag=#SA_Exclusive,False
ScrTags(10)\ti_Tag=#SA_Draggable,True
ScrTags(11)\ti_Tag=#SA_AutoScroll,False
ScrTags(12)\ti_Tag=#TAG_DONE,0
ScrTags(13)\ti_Tag=#TAG_DONE,0
UsedChip.l=((320 LSR 3)*240)*8 ; With test params (depth 8)
FreeChip.l=AvailMem_(#MEMF_CHIP)
Forbid_
If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
NowChip.l=AvailMem_(#MEMF_CHIP)
Permit_
If FreeChip-NowChip<UsedChip
; Graphics card screen
IsAGA=False
PrefDisplayWidth AND $FFF0 ; For gfx-cards, width to nearest 16
ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
ScrTags(8)\ti_Tag=#SA_DClip,&Rect
VWait 5 ; seems to be necessary (safer)
Free Screen 0
VWait 5
If ScreenTags(0,Title$,&ScrTags(0))<>0
For Loop.w=0 To PrefDisplayBuffering-1
If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
Menus Off
ScreensBitMap 0,Loop
*TmpBmp.bitmap=Addr BitMap(Loop)
Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
For DLoop.w=0 To 8-1 ; Depth of 8
*TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
Next DLoop
Next Loop
Else
Function Return False
EndIf
Else
; AGA screen
IsAGA=True
PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
ScrTags(8)\ti_Tag=#SA_DClip,&Rect
ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
Forbid_
VWait 5 ; seems to be necessary (safer)
Free Screen 0
VWait 5
For Loop.w=0 To PrefDisplayBuffering-1
If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
If AvailMem_(#MEMF_CHIP)>=(PrefDisplayWidth*PrefDisplayHeight)+16
Memory.l=AllocMem((PrefDisplayWidth*PrefDisplayHeight)+16,$10002) ; Chip bitmap
Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
If Memory<>0
CludgeBitMap Loop,PrefDisplayWidth,PrefDisplayHeight,8,Memory ; Depth 8
If Loop=0
ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
If ScreenTags(0,Title$,&ScrTags(0))=0
Permit_
Function Return False
EndIf
EndIf
If Window(Loop,0,0,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
Menus Off
Else
Permit_
Function Return False
EndIf
Else
Permit_
Function Return False
EndIf
PlanarBuf(Loop)=Memory
Next Loop
Permit_
EndIf
DEFTYPE.DimensionInfo DimInfoBuf
GetDisplayInfoData_ FindDisplayInfo_(PrefDisplayID) AND $FFFFFFFF,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
PrefDisplayLeft.w=((DimInfoBuf\TxtOScan\MaxX)-PrefDisplayWidth)/2
PrefDisplayTop.w=((DimInfoBuf\TxtOScan\MaxY)-PrefDisplayHeight)/2
*Scr._Screen=Peek.l(Addr Screen(0))
*ScrVP=ViewPort(0)
*ScrVP\DxOffset=PrefDisplayLeft,PrefDisplayTop
ScrollVPort_ *ScrVP
RethinkDisplay_
Menus Off
If *ScrVP\DHeight<>PrefDisplayHeight
Forbid_
*Scr\Height=PrefDisplayHeight ; Enforce y clipping
Permit_
EndIf
ScreenToFront_ *Scr
Function Return True
Else
Permit_
Function Return False
EndIf
End Function
.Main
#ObjSize=160
InitPalette 0,256
If InitDisplay{"Game"}=False Then Goto Finish
InitBank 0,PrefDisplayWidth*PrefDisplayHeight,$10000
CludgeBitMap 4,PrefDisplayWidth,PrefDisplayHeight,8,Bank(0)
LoadBitMap 4,"Orion.IFF",0
ShowPalette 0
*RP._RastPort=RastPort(0)
Mc2pWindow 0,PrefDisplayWidth,PrefDisplayHeight ; Need this line in some form or other
MCludgeBitmap 4,PrefDisplayWidth,PrefDisplayHeight*PrefDisplayBuffering,*RP\_BitMap\Planes
MBitmap 0,PrefDisplayWidth,PrefDisplayHeight+#ObjSize
MPlanar16ToBitmap 0,Bank(0),PrefDisplayWidth,PrefDisplayHeight,PrefDisplayWidth,PrefDisplayHeight
MBitmap 1,PrefDisplayWidth,PrefDisplayHeight+#ObjSize
MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
MUseBitmap 0
MGetaShape 0,128,60,#ObjSize,#ObjSize
MQueue 0,1
.Table
VWait 5
MTable 0,256*256
;*** precalculated ***
If ReadFile(0,"Orion.Table")=0 Then Goto Finish
ReadMem 0,MTablePtr,256*256
CloseFile 0
;*** precalculated ***
;*** runtime ***
;Dim R(256),G(256),B(256)
;PaletteInfo 0
;For c=0 To 255
; R(c)=AGAPalRed(c)
; G(c)=AGAPalGreen(c)
; B(c)=AGAPalBlue(c)
;Next c
;TP.l=MTablePtr
;For SourceColour=0 To 255
; For DestColour=0 To 255
; Offset.l=(SourceColour LSL 8)+DestColour
;R0=(R(SourceColour)+R(DestColour)) LSR 1
;G0=(G(SourceColour)+G(DestColour)) LSR 1
;B0=(B(SourceColour)+B(DestColour)) LSR 1
;;R0=Min((R(SourceColour)+R(DestColour)),255)
;;G0=Min((G(SourceColour)+G(DestColour)),255)
;;B0=Min((B(SourceColour)+B(DestColour)),255)
;;R0=R(DestColour)*0.8
;;G0=G(DestColour)*0.8
;;B0=B(DestColour)*0.8
; Best=0
; BestTotal.l=$0FFFFFFF
; For TestColour=0 To 255
; R1=R(TestColour)
; G1=G(TestColour)
; B1=B(TestColour)
; Total.l=((R0-R1)*(R0-R1))+((G0-G1)*(G0-G1))+((B0-B1)*(B0-B1))
; If Abs(Total)<BestTotal
; Best=TestColour
; BestTotal=Abs(Total)
; EndIf
; Next TestColour
; Poke.b TP+Offset,Best
; Next DestColour
;Next SourceColour
;;*** runtime ***
;;Save off the generated table here
;If WriteFile(0,"Orion.Table")=False Then Goto Finish
;WriteMem 0,MTablePtr,256*256
;CloseFile 0
.Loop
buf.b=0
its.l=0
cnt.b=0
MQBlitMode MReMapMode
ResetTimer
While Joyb(0)=0 AND Joyb(1)=0
MQBlit SMouseX,SMouseY
;Display
If IsAGA
Mc2p MBitmapPtr(0),PlanarBuf(buf)
ShowBitMap buf
If PrefDisplayBuffering>1
buf+1
If buf=PrefDisplayBuffering Then buf=0
EndIf
Else
MUseBitmap 4
If PrefDisplayBuffering>1
MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,PrefDisplayHeight+(cnt*PrefDisplayHeight),0
*RP0._RastPort=RastPort(0)
*RP1._RastPort=RastPort(Min(PrefDisplayBuffering-1,1+cnt))
ClipBlit_ *RP1,0,0,*RP0,0,0,PrefDisplayWidth,PrefDisplayHeight,$C0
If PrefDisplayBuffering=3 Then cnt=1-cnt ; Toggle output buffer
Else
MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
EndIf
MUseBitmap 0
EndIf
MUnQueue 0,1
its+1
Wend
;Report
t=Timer
t=Max(t,1)
its=Max(its,1)
a.q=50.0/(t/its)
;SaveBitmap 0,"Ram:Snap.IFF",0
WBenchToFront_
FindScreen 1
Window 2,16,16,300,40,0,"Test results",1,0
WindowOutput 2
NPrint a," frames per second"
NPrint " "
NPrint "Press mouse/joy button..."
Repeat
Until Joyb(0)<>0 OR Joyb(1)<>0
Finish:
End